package com.itheima.day06.myException.test5;

import java.util.Scanner;

public class NewTest {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("开始创建用户");
        User u = new User();
        String name;
        int age;
        System.out.println("请输入用户姓名");
        name = sc.next();
        u.setName(name);
        while (true){
            System.out.println("前请输入学生年龄");
            String agestr = sc.next();
            try {
                age = Integer.parseInt(agestr);
                u.setAge(age);
            } catch (NumberFormatException e){
                System.out.println("请输入正确数字字符\n");
                continue;
            } catch (NumberOutOfBoundsException e){
                System.out.println("年龄未在范围\n");
                continue;
            }
            System.out.println("创建成功");
            break;
        }
        System.out.println(u.toString());
    }
}
